
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>{if $Request.param.type =='unread'}{if $unread >0}新未读消息 {$unread} 条{else}暂无未读消息{/if}{elseif $Request.param.type =='read'}已读 {else}全部{/if} - 我的消息 - 用户中心</title>
 {include file="public/css"}
</head>
<body>

{include file="public/header"}

<div class="layui-container fly-marginTop fly-user-main">
<!-- 左侧导航 -->
    <div class="user-left-menu" >
    {include file="public/left_menu"}
    </div>

  
  <div class="fly-panel fly-panel-user user-right-content" pad20>
	  <div class="layui-tab layui-tab-brief" lay-filter="user" id="LAY_msg" style="margin-top: 15px;">
      <button class="layui-btn layui-btn-normal" id="delallmsg">标记已读</button>
    

          <div class="layui-tab  layui-tab-brief">
            <ul class="layui-tab-title">
              <li {if empty($Request.param.type)} class="layui-this" {/if}><a href="{:url('message/index')}">全部</a></li>
              <li {if $Request.param.type =='unread'} class="layui-this" {/if}><a href="{:url('message/index',['type'=>unread])}">未读 {if $unread>0 }<span class="layui-badge">{if $unread>1000}1000+{else}{$unread}{/if}</span>{/if}</a></li>
              <li {if $Request.param.type =='read'} class="layui-this" {/if}><a href="{:url('message/index',['type'=>read])}">已读 </a></li>
            </ul>
            <div class="layui-tab-content">
              <!-- 表格内容 -->
                 <div class="layui-row">            
                   <table id="table"></table>
                </div>  

              </div>
   
          </div> 


	  </div>
	</div>

</div>
<!-- 会员底部文件 -->
{include file="public/footer"}

{include file="public/js"}
<script>
//Demo
layui.use(['form','table','laypage','laydate'], function(){
  var form = layui.form;
  var table = layui.table;
  var type= "{$Request.param.type}";
 var where = {token: 'sasasas',type:type};

 ajax_table(where);



//获得数据表格函数
function ajax_table(where=""){
     table.render({
      elem: '#table'
      ,limit:10
      // ,width:910
      // ,height:515
      ,where:where
      ,url: '{:url("message/index")}' //数据接口
      ,page: {layout:['prev', 'page', 'next']} //开启分页
      ,loading:false

      ,skin: 'line' //行边框风格
         ,text: {
      none: "没有更多数据" //默认：无数据。注：该属性为 layui 2.2.5 开始新增
      }
    ,even: true //开启隔行背景
    ,size: 'lg' //小尺寸的表格
      ,cols: [[ //表头

      {field: 'mid', title: "编号", width:80,sort: true,templet: '#midTpl'}
      ,{field: 'type', title: "类型", width:90,templet: '#typeTpl'}
      ,{field: 'title', title: "标题",templet: '#titleTpl'}
      ,{field: 'create_time', title: "时间", width:150}
      ,{field: 'status', title: "操作", width:80,templet: '#statusTpl'}
      // ,{field: 'create_time', title: "时间"} 
      ]]
    });
}

});
</script>
<script type="text/html" id="typeTpl">
{{#  if(d.type == 0){ }}
   【通知】
{{#  } else if(d.type == 1){ }}
   【私信】
{{#  } }}
</script>
<script type="text/html" id="midTpl">
{{#  if(d.is_read == 0){ }}
<input type="checkbox" name="mid[]" class="id " title=""  lay-skin="primary" value="{{d.mid}}">
  {{#  } else{ }}
  
{{#  } }}
</script>

<script type="text/html" id="statusTpl">
<a href="{:url('message/detail')}?mid={{d.mid}}">查看</a>
</script>

<script>
  $(function(){
    //全选批量删除
        var id = []; //定义空数组
        var url ="{:url('message/updateRead')}"; //请求的url
        var data = {"id":id};   //传递的表单数据
        var delButton = "#delallmsg"; //删除节点class 或者ID
        var checkboxClass = ".id"; //多选框class
       

         $(delButton).click(function(){
              $(checkboxClass).each(function() {
              if(this.checked == true){
                   id.push($(this).val()); 
              }
              });              
         if(id.length == 0){
            parent.layer.alert('你没有选中任何消息',{title:'批量消息操作'});
         }else{
           
                    // 确定ajax 删除数据
                                $.post(url,data        
                                     ,function(json){
                                      if(json.code == 0){
                                          layer.msg(json.msg);
                                               setTimeout(function(){ 
                                                     window.location.reload();  //页面刷新
                                                },1000);
                                           }
                                         }
                                       );
            id = [];
         }

    });
  });
</script>


</body>
</html>